//
// Created by mio on 25-5-14.
//

#ifndef RTMPPUSHMANAGER_H
#define RTMPPUSHMANAGER_H

#include <thread>
#include <memory>
#include <QString>
#include <atomic>

#include "EventLoop.h"
#include "RtmpPublisher.h"


class VideoCapture;
class AudioEncoder;
class VideoEncoder;
class AudioCapture;


class RtmpPushManager
{
public:
    virtual ~RtmpPushManager();
    RtmpPushManager();
public:
    bool Open(const QString& str);
    bool isClose(){return isConnect == false;}
protected:
    bool Init();
    void Close();
    void EncodeVideo();
    void EncodeAudio();
    void StopEncoder();
    void StopCapture();
    bool IsKeyFrame(const uint8_t* data, uint32_t size);
    void PushVideo(const quint8* data, quint32 size);
    void PushAudio(const quint8* data, quint32 size);
private:
    std::atomic_bool exit_ = false;
    bool isConnect = false;
    EventLoop* loop_ = nullptr;
    std::unique_ptr<AudioEncoder>  audio_encoder_;
    std::unique_ptr<VideoEncoder> video_encoder_;
    std::unique_ptr<EventLoop> event_loop_;
    std::shared_ptr<RtmpPublisher> pusher_;
    std::unique_ptr<AudioCapture> audio_Capture_;
    std::unique_ptr<VideoCapture> screen_Capture_;
    std::unique_ptr<std::thread>  audioCaptureThread_ = nullptr;
    std::unique_ptr<std::thread>  videoCaptureThread_ = nullptr;
};



#endif //RTMPPUSHMANAGER_H
